<?php  
$path = drupal_get_path('module', 'website_directory'); 
drupal_add_css($path . '/css/website_directory.css');
drupal_add_js($path . '/js/website_directory.js');

function website_directoryhome(){ 
global $base_url;
global $language;
 if($language->language=='ta'){
	$lang= 'ta';
 }else{
 	$lang='';
 }
	$url = $base_url . '/' . drupal_get_path('module', 'website_directory');
	$output .='<div class="node_view_heading"><div class="node_view_head_content">';
	$output .='<img width="15" height="15" src= "'.$url.'/images/2leftcurve.jpg" " alt="" class="node_view_top_corner" style="display: none;"> ';
	$output .='<span class="node_view_head_title"><br>'.t('Important Websites').'</span></div></div>';
	        
    my_db_change(1);   
    $result = db_query("SELECT distinct wcid,website_cat_name FROM website_category_mst  ORDER BY website_cat_name ASC");
	my_db_change(0);
	$op = '<div class="node_viewlist_wd">';
	$st =1;
	foreach ($result as $dept) {
	 	if($st%2!=0) { 
			$cls = "first_clmd";
		} 
		else {
			$cls = "second_clmd";
		}
	
		 $op .= "<div class='".$cls." d".$dept->wcid."'>";
		 $op .= "<img src='".$url."/images/icon_main.png' alt='More' /> "; 
		 $op .= l(trim(t($dept->website_cat_name)),$lang.'/website_directory/'.$dept->wcid)."</div>";	 
		 
		 $st++;

	}
	$op .="</div>";
	$output .= $op;
	$output .= '<div class="node_view_bottom"><div class="node_view_bottom_content">
		<img width="15" height="15" src="'.$url.'/images/1bottomleft.jpg" alt="" class="node_view_bottom_corner" style="display: none;"></div>
</div>';	
	return $output;
}
function website_links_data(){
global $base_url;
global $language;
$cat = arg(1);
 if($language->language=='ta'){
	$lang= 'ta';
 }else{
 	$lang='';
 }
	$url = $base_url . '/' . drupal_get_path('module', 'website_directory');
	my_db_change(1);
	$query = new EntityFieldQuery();
	$query->entityCondition('entity_type', 'node')
	  ->entityCondition('bundle', 'website_entry')   
	  ->fieldCondition('field_web_categorys', 'value', $cat, '=')
	  ->propertyCondition('status',1)
	  ->propertyCondition('language', $lang, '=');
	  
	$result = $query->execute();
	
	$nid = current($result['node']);
	
	if (isset($result['node'])) {
	  $news_items_nids = array_keys($result['node']);	  
	  $news_items = entity_load('node', $news_items_nids);
	}
	//print "<pre>";print_r($news_items);print "</pre>";
	my_db_change(0);
	$output .='<div class="node_view_heading"><div class="node_view_head_content">';
	$output .='<img width="15" height="15" src= "'.$url.'/images/1leftcurve.jpg" " alt="" class="node_view_top_corner" style="display: none;"> ';
	$output .='<span class="node_view_head_title"><br>'.t('Important Links : ').t(category_weblinks_name($cat)).'</span></div></div>';
	$output .= '<div class="node_viewlist_wd">';
	$st =1;
	foreach ($news_items as $dept) {
		$urval = $dept->field_web_url['und'][0]['value'];
		if($urval){
			$urval ="'$urval'";
		}
		else{
			$urval ="'http://www.tn.gov.in'";
		}
	 	if($st%2!=0) { 
			$cls = 'first_clmd';
		} 
		else {
			$cls = 'second_clmd';
		}
	
		 $op .= '<div class="'.$cls.'">';
		 $op .= '<img src="'.$url.'/images/icon.png" alt="More" /> '; 
		 $op .= '<a onclick="return tnportal_window('.$urval.');" href="javascript:void(0);">'.$dept->title.'</a>';	 
		 $op .= '</div>';
		 $st++;

	}	
	if($st !='1'){
		$output .= $op;
	}
	else {
		$output .= '<div class="no_record">No Results Found</div>';
	}
	$output .="</div>";
	$output .= '<div class="node_view_bottom"><div class="node_view_bottom_content">
		<img width="15" height="15" src="'.$url.'/images/1bottomleft.jpg" alt="" class="node_view_bottom_corner" style="display: none;"></div>
</div>';	
	
	return $output;
}